package chapter21.section4;

import java.io.InputStream;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/1/28 11:13
 */
public class IOBlocked implements Runnable {
    private final InputStream inputStream;

    public IOBlocked(InputStream inputStream) {
        this.inputStream = inputStream;
    }

    @Override
    public void run() {
        try {
            System.out.println("Waiting for read():");
            inputStream.read();
        } catch (Exception e) {
            if (Thread.currentThread().isInterrupted()) {
                System.out.println("Interrupted from blocked I/O");
            } else {
                e.printStackTrace();
            }
        }

        System.out.println("Exiting IOBlocked.run()");
    }
}
